home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr13 / txt_srch.zip / TXT_SRCH.BAS next >
BASIC Source File  |  1995-01-17  |  5KB  |  83 lines

  1.        CLS  ' This program requires QUICK BASIC 4.5 to run the source code or compile.
  2.         ' This program is freeware and may be used by anyone freely.
  3.         ' written 1/15/95 by Van Lincoln as a programming example.
  4.        PRINT "This program finds a specific string(s) in the text database"
  5.        PRINT "and then shows you the database entry information, optionally"
  6.        PRINT "producing a printed copy of the information on your printer."
  7.        PRINT "Make sure that your PRINTER is ON and ready to print !"
  8.        PRINT "Press the <Esc> key anytime to halt processing  and return to main program"
  9.     '----------------------------------------------------
  10. 80     LOCATE 7, 1: INPUT "ENTER THE DATABASE FILE NAME TO SEARCH :"; IFILE$ ' input file name
  11. 84     ON ERROR GOTO 850
  12. 90     OPEN IFILE$ FOR INPUT AS #1
  13.        OPEN IFILE$ FOR INPUT AS #2
  14. 100    LOCATE 9, 1
  15. 104    INPUT "Enter the '1st String of characters' that you wish to find : ", SS1$ ' Search string
  16. 108    INPUT "do you want to enter a '2nd' string  Y/N "; yn$: yn$ = LCASE$(yn$)
  17. 110    IF yn$ <> "y" THEN 118
  18. 111    INPUT "(A)nd / (O)r  for the 1st and 2nd strings (A/O) "; ao$: ao$ = LCASE$(ao$)
  19. 112    INPUT "Enter the '2nd String of characters' that you wish to find : ", ss2$ ' Search string
  20. 116    ss2$ = LCASE$(ss2$)  'convert to lower case if uppercase
  21. 118    SS1$ = LCASE$(SS1$)  'convert to lower case if uppercase
  22. 120    LOCATE 13, 1
  23. 130    INPUT "Output to (S)creen or (P)rinter or (B)oth? (S,P,B) : ", TO.PRINT$
  24. 135    TO.PRINT$ = LCASE$(TO.PRINT$) ' convert to lowercase if uppercase
  25.        VIEW PRINT 15 TO 25
  26. 140    IF TO.PRINT$ = "s" THEN CRT% = -1: GOTO 210
  27. 150    IF TO.PRINT$ = "p" THEN PRT% = -1: GOTO 170
  28. 160    CRT% = -1: PRT% = -1
  29. 165    '------------------------------------------------------------------------
  30. 170    LPRINT "THIS LIST WAS PRODUCED ON "; DATE$; "  AT "; TIME$; " and has found"
  31. 180    LPRINT "the selected strings in the following text database entries..."
  32. 190    LPRINT CHR$(15) + CHR$(27) + CHR$(48);
  33. 195    WIDTH LPRINT 132
  34. 200   '---------------------------------------------------------------
  35. 210    IF EOF(1) THEN 450
  36. 220      LINE INPUT #1, LIN$     ' input a line of the database
  37. 221      nLIN$ = LIN$            ' preserve original line case
  38. 222      LIN$ = LCASE$(LIN$)     ' make data lowercase
  39. 225      GOSUB 900               ' Was Esc key pressed to exit?
  40. 230      ICOUNT! = ICOUNT! + 1   ' Count lines incoming
  41. 240      GOSUB 510               ' Show operation with line number
  42. 250      fs1% = INSTR(LIN$, SS1$)  ' Found String 1?
  43. 251      IF yn$ <> "y" THEN IF fs1% < 1 GOTO 440 ELSE 270 ' no=only 1 string
  44. 252      fs2% = INSTR(LIN$, ss2$)  ' Found String 2?
  45. 254      IF ao$ = "a" THEN IF fs1% > 0 AND fs2% > 0 THEN GOTO 270 ELSE 440
  46. 258      IF ao$ = "o" THEN IF fs1% > 0 OR fs2% > 0 THEN GOTO 270 ELSE 440
  47. 270      IF PRT% <> 0 THEN LPRINT ICOUNT!; " "; nLIN$
  48. 280      IF slow% = 1 THEN FOR I = 1 TO 10000: NEXT I
  49. 282      IF slow% = 2 THEN FOR I = 1 TO 20000: NEXT I
  50. 284      IF slow% = 3 THEN GOSUB 900: GOTO 284
  51. 288      IF CRT% <> 0 THEN PRINT ICOUNT!; " "; nLIN$
  52.        '
  53. 300    '----------------------------------------------------------------
  54. 440    IF NOT EOF(1) THEN 210
  55. 450    PRINT : GOTO 940
  56.        '---------------------------------------------------------------
  57.        ' ---- Upper right corner line numbers to show operation. ----
  58.        '---------------------------------------------------------------
  59. 510    SROW% = CSRLIN: SCOL% = POS(0)  ' Save old cursor position
  60.        LOCATE 16, 74: PRINT "      "; : LOCATE 16, 74:  PRINT ICOUNT;
  61.        LOCATE SROW%, SCOL%
  62.        RETURN
  63.       '---------In case of errors come here -------------
  64. 850    BEEP: PRINT "Error "; ERR; " at line "; ERL
  65.        IF ERL = 80 THEN PRINT "Input file not found  : "; IFILE$
  66.        RESUME 890
  67. 890    SYSTEM
  68.       '------------ If escape key is pressed do this -----
  69. 900    ZZ$ = INKEY$
  70.        ZZ$ = LCASE$(ZZ$)
  71.        IF ZZ$ = "s" THEN GOSUB 1100
  72. 920    IF ZZ$ <> CHR$(27) THEN RETURN               ' Esc key falls through
  73. 940    IF PRT% <> 0 THEN LPRINT : LPRINT CHR$(12)   ' Final form feed
  74.        PRINT : PRINT "Finished search for "; SS1$; " "; ss2$; " in "; IFILE$
  75.        CLOSE
  76.        SYSTEM
  77.       '------------ If "S" PRESSED THEN SLOW   -------------
  78. 1100   IF slow% = 0 THEN slow% = 1: RETURN
  79.        IF slow% = 1 THEN slow% = 2: RETURN
  80.        IF slow% = 2 THEN slow% = 3: RETURN
  81.        IF slow% = 3 THEN slow% = 0: RETURN
  82.  
  83.